<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="demo-form-inline">
      <el-form-item label="店名">
        <el-input v-model="queryParams.name" placeholder="店名" />
      </el-form-item>
      <!-- <el-form-item label="地址">
        <el-select v-model="queryParams.entityProductTypeId" placeholder="请选择">
          <el-option v-for="item in productTypeList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-button type="primary" style="margin-bottom: 15px;" @click="onInsert">新增</el-button>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="id" prop="id" width="95" />
      <el-table-column label="店名" align="center" prop="name" />
      <el-table-column label="封面图" align="center" prop="cover">
        <template slot-scope="scope">
          <el-image :src="scope.row.cover" style="width: 100px; height: 100px" />
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="地址" align="center" prop="address" />

      <el-table-column label="店铺标签" align="center" prop="tags" />
      <el-table-column label="店铺类型" align="center" prop="entityProductTypeId">
        <template slot-scope="scope">
          {{ getTypeText(scope.row.entityProductTypeId) }}
        </template>
      </el-table-column>
      <el-table-column label="预计开业时间" align="center" prop="expectedOpeningTime" />
      <!-- <el-table-column label="店铺面积" align="center" prop="extent" />
      <el-table-column label="店铺总投资" align="center" prop="totalInvestAmount" />
      <el-table-column label="毛利率" align="center" prop="grossMargin" />
      <el-table-column label="起投金额" align="center" prop="minInvestAmount" /> -->
      <el-table-column label="排序权重" align="center" prop="sort" />


      <!-- <el-table-column label="需要投资金额" align="center" prop="amount" />
      <el-table-column label="股权比例" align="center" prop="stockOptionsRate" />
      <el-table-column label="投资截止时间" align="center" prop="endTime" /> -->
      <el-table-column label="分红周期" align="center" prop="dividendCycle" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <!-- <el-button type="text" style="color: red;" size="mini" @click="handleEdit(scope.row)">删除</el-button> -->
          <el-button type="text" size="mini" @click="handleStatus(scope.row)">{{ scope.row.status == 1 ? '下架' :
            '上架' }}</el-button>
        </template>
      </el-table-column>


    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="fetchData" @current-change="fetchData" />
    </div>
    <showInfo ref="showInfo" />
    <add ref="add" />

  </div>
</template>

<script>
import showInfo from './showInfo.vue'
import add from './add.vue'
import { entityPage, productDelete, typeList } from '@/api/table'
export default {
  components: {
    showInfo,
    add
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      timer: null,
      statusOptions: [
        { label: '正常', value: '1' },
        { label: '禁用', value: '0' }
      ],
      sortByList: [
        { id: 'trx_balance', text: '余额' },
        { id: 'insurance_balance', text: '保险仓余额' },
        { id: 'fuel', text: 'wk余额' },
        { id: 'fix_insurance_balance', text: 'ai托管金额' }
      ],
      queryParams: {

        pageSize: 10,
        pageNum: 1,
        entityProductTypeId: '',
        name: '',
      },
      productTypeList: []
    }
  },
  created() {
    this.fetchData()
    this.getProductTypeList()
  },
  destroyed() { },
  methods: {
    handleStatus(record) {
      this.$confirm(
        '此操作将' + (record.status == 1 ? '下架' : '上架') + ', 是否继续?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(async () => {
        await productDelete({
          id: record.id,
          status: record.status == 1 ? 0 : 1
        })
        this.fetchData()
      })
    },
    getTypeText(id) {
      let str = ''
      this.productTypeList.map(item => {
        if (item.id == id) {
          str = item.name
        }
      })
      return str
    },
    async getProductTypeList() {
      const res = await typeList({ pageNum: 1, pageSize: 100 })
      this.productTypeList = res.data.records


    },
    handleTd(record, index) {
      console.log('....................')
      this.$refs.td.show(record, index)
    },
    handleBill(record) {
      this.$refs.children.show(record)
    },
    handleC(record) {
      this.$refs.addC.show(record)
    },
    // handleChildren(record) {
    //   this.$refs.children.show(record)
    // },
    handleUser(record) {
      this.$refs.userComponents.show(record)
    },

    fetchData() {
      this.listLoading = true
      entityPage(this.queryParams).then((response) => {
        response.data.records.map((item) => {
          if (item.status === 1) {
            item.statusB = true
          } else {
            item.statusB = false
          }
          console.log(item.statusB)
        })
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    handleShowInfo(e) {
      this.$refs.add.edit(e)
    },
    onSubmit() {
      this.queryParams.pageNum = 1
      this.fetchData()
    },
    reset() {
      this.queryParams = {
        pageSize: 10,
        pageNum: 1,

        name: '',
      }
      this.fetchData()
    },
    onInsert(record) {
      this.$refs.add.show(record)
    },
    handleEdit(e) {
      this.$refs.add.edit(e)
    }
  }
}
</script>
